'''
Created on 20.3.2012

@author: mphkh
'''
from datetime import date
from CashFlowUtils.IceBonds import *
from TimeUtils.daycount import *
from TimeUtils.utils import *


def fwdPrice(bond, cleanprice, rate, valuedate, fwddate):
    cf = bond.remaining_cashflows_todate(valuedate, fwddate)
    
    dcoupons = 0.0
    
    for obj in cf:
        print obj.yearfrac, obj.daysPeriod, obj.amount
        dcoupons = dcoupons + obj.amount/(1+rate*obj.yearfrac) 
    
    price = bond.cleantodirty(valuedate, cleanprice)
    
    yf = yearfraction(valuedate, fwddate, DayCountBasis.basis_act360)
    
    fwdprice = (price - dcoupons)*(1+yf*rate)
    return fwdprice
